package com.ruoyi.devops.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.devops.domain.LargeScreenComprehensive;
import com.ruoyi.devops.domain.LargeScreenComprehensivesa;
import com.ruoyi.devops.mapper.LargeScreenMapper;
import com.ruoyi.devops.mapper.LargeScreenSaMapper;
import com.ruoyi.devops.service.ILargeScreenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class LangeScreenService extends ServiceImpl<LargeScreenMapper,LargeScreenComprehensive> implements ILargeScreenService {

    @Resource
    LargeScreenMapper largeScreenMapper;

    @Resource
    LargeScreenSaMapper largeScreenSaMapper;

    public List<LargeScreenComprehensive> queryData(){
        List<LargeScreenComprehensive> list =largeScreenMapper.queryData();

        return list;
    }


    public List<LargeScreenComprehensive> queryDataOne(){
        List<LargeScreenComprehensive> list =largeScreenMapper.queryDataOne();

        return list;
    }


    public List<LargeScreenComprehensive> queryAll(){
        List<LargeScreenComprehensive> list =largeScreenMapper.queryAll();

        return list;
    }
    public List<LargeScreenComprehensive> queryAlls(){
        List<LargeScreenComprehensive> list =largeScreenMapper.queryAlls();

        return list;
    }
    @Transactional
    public List<LargeScreenComprehensive> updateData(List<String> list){
        for(String name:list){
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("name",name);
            LargeScreenComprehensive largeScreenComprehensive = (LargeScreenComprehensive) largeScreenMapper.selectList(wrapper).get(0);
            largeScreenComprehensive.setIsClick(1);
            largeScreenMapper.updateById(largeScreenComprehensive);
        }

        List<LargeScreenComprehensive> largeScreenComprehensives = largeScreenMapper.selectList(new QueryWrapper<>());
        for(LargeScreenComprehensive l:largeScreenComprehensives){

            boolean flag = true;
            for(String name:list){
                    if(l.getName().equals(name)){
                        flag = true;
                        break;
                    }else{
                        flag=false;
                    }
            }
            if(!flag){
                l.setIsClick(0);
                this.updateById(l);
            }

        }




        List<LargeScreenComprehensive> arr=largeScreenMapper.queryData();
        return arr;
    }


    public List<LargeScreenComprehensive> updateData1(List<String> list){
        for(String name:list){
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("name",name);
            //他妈的怎么能好使阿？
            // 截取前4个拼一下 差不对得了


            LargeScreenComprehensivesa largeScreenComprehensive = (LargeScreenComprehensivesa) largeScreenSaMapper.selectList(wrapper).get(0);
            largeScreenComprehensive.setIsClick1(1);
            largeScreenSaMapper.updateById(largeScreenComprehensive);
        }

        List<LargeScreenComprehensivesa> largeScreenComprehensives = largeScreenSaMapper.selectList(new QueryWrapper<>());
        for(LargeScreenComprehensivesa l:largeScreenComprehensives){

            boolean flag = true;
            for(String name:list){
                if(l.getName().equals(name)){
                    flag = true;
                    break;
                }else{
                    flag=false;
                }
            }
            if(!flag){
                l.setIsClick1(0);
                largeScreenSaMapper.updateById(l);
            }

        }




        List<LargeScreenComprehensive> arr=largeScreenMapper.queryDataOne();
        return arr;
    }
}
